package com.pid.customerflow.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pid.common.annotation.Log;
import com.pid.common.core.controller.BaseController;
import com.pid.common.core.domain.AjaxResult;
import com.pid.common.enums.BusinessType;
import com.pid.customerflow.domain.WorkflowBigcustomer;
import com.pid.customerflow.service.IWorkflowBigcustomerService;
import com.pid.common.utils.poi.ExcelUtil;
import com.pid.common.core.page.TableDataInfo;

/**
 * 大客户流程Controller
 * 
 * @author pid
 * @date 2022-03-01
 */
@RestController
@RequestMapping("/system/bigcustomer")
public class WorkflowBigcustomerController extends BaseController
{
    @Autowired
    private IWorkflowBigcustomerService workflowBigcustomerService;

    /**
     * 查询大客户流程列表
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowBigcustomer workflowBigcustomer)
    {
        startPage();
        List<WorkflowBigcustomer> list = workflowBigcustomerService.selectWorkflowBigcustomerAndTaskNameList(workflowBigcustomer);
        return getDataTable(list);
    }

    /**
     * 查询历史流程列表
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(WorkflowBigcustomer workflowBigcustomer) {
//        startPage();
        //倒序
        startPageByIdDesc();
        List<WorkflowBigcustomer> list = workflowBigcustomerService.selectWorkflowBigcustomerList(workflowBigcustomer);
        return getDataTable(list);
    }
    /**
     * 导出大客户流程列表
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:export')")
    @Log(title = "大客户流程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkflowBigcustomer workflowBigcustomer)
    {
        List<WorkflowBigcustomer> list = workflowBigcustomerService.selectWorkflowBigcustomerList(workflowBigcustomer);
        ExcelUtil<WorkflowBigcustomer> util = new ExcelUtil<WorkflowBigcustomer>(WorkflowBigcustomer.class);
        return util.exportExcel(list, "大客户流程数据");
    }

    /**
     * 获取大客户流程详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:bigcustomer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(workflowBigcustomerService.selectWorkflowBigcustomerById(id));
    }

    /**
     * 新增大客户流程
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:add')")
    @Log(title = "大客户流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowBigcustomer workflowBigcustomer)
    {
        return toAjax(workflowBigcustomerService.insertWorkflowBigcustomer(workflowBigcustomer));
    }

    /**
     * 修改大客户流程
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:edit')")
    @Log(title = "大客户流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowBigcustomer workflowBigcustomer)
    {
        if (Integer.parseInt(workflowBigcustomer.getState()) != 0){
            workflowBigcustomer.setDelFlag("1");
        }
        workflowBigcustomerService.updateWorkflowBigcustomer(workflowBigcustomer);
        return toAjax(workflowBigcustomerService.insertWorkflowBigcustomer(workflowBigcustomer));
    }

    /**
     * 删除大客户流程
     */
    @PreAuthorize("@ss.hasPermi('system:bigcustomer:remove')")
    @Log(title = "大客户流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(workflowBigcustomerService.deleteWorkflowBigcustomerByIds(ids));
    }
}
